<?php
class Customer
{
	public $Table="customer";
	public $CustomerID;
	public $CustomerName;
	public $Email;
	public $Address;
	public $ShippingAddress;
	public $Tel;
	public $Cellphone;
	public $Company;
	public $Pass;
	
	function loadByKey($id)
	{
		$ob=new ClassConnect();
		$sql="select * from `".$this->Table."` where CustomerID='".$id."'";
		$row=$ob->singleData($sql);
		$this->CustomerID=$row['CustomerID'];
		$this->CustomerName=$row['CustomerName'];
		$this->Email=$row['Email'];
		$this->Address=$row['Address'];
		$this->ShippingAddress=$row['ShippingAddress'];
		$this->Tel=$row['Tel'];
		$this->Tel=$row['Cellphone'];
		$this->Tel=$row['Company'];
		$this->Pass=$row['Pass'];
	}
	function getTable($dk)
	{
		$ob=new ClassConnect();
		$sql="select * from `".$this->Table."` $dk";
		$data=$ob->mutiData($sql);
		return $data;
	}
	function travel($dk)
	{
		$arr=array();
		$data=$this->getTable($dk);
		for($i=0;$i<count($data);$i++)
			array_push($arr,$data[$i]['CustomerID']);
		return $arr;
	}
	function insert($conn)
	{
		$ob=new ClassConnect();
		$field=array("CustomerID",
					"CustomerName",
					"Email",
					"Address",
					"ShippingAddress",
					"Tel",
					"Cellphone",
					"Company",
					"Pass");
		$value=array($this->CustomerID,
					$this->CustomerName,
					$this->Email,
					$this->Address,
					$this->ShippingAddress,
					$this->Tel,
					$this->Cellphone,
					$this->Company,
					$this->Pass);
		return $ob->insertData($conn,$this->Table,$field,$value);
	}
	function update($conn)
	{
		$ob=new ClassConnect();
		$field=array("CustomerID",
					"CustomerName",
					"Email",
					"Address",
					"ShippingAddress",
					"Tel",
					"Cellphone",
					"Company",
					"Pass");
		$value=array($this->CustomerID,
					$this->CustomerName,
					$this->Email,
					$this->Address,
					$this->ShippingAddress,
					$this->Tel,
					$this->Cellphone,
					$this->Company,
					$this->Pass);
		$where="CustomerID = '".$this->CustomerID."'";
		
		return $ob->updateData($conn,$this->Table,$field,$value,$where);			
	}
	
	function delete($conn)
	{
		$ob=new ClassConnect();		
		$where="CustomerID = '".$this->CustomerID."'";
		return $ob->deleteData($conn,$this->Table,$where);
			
	}
	function checkID($id)
	{
		$data=$this->travel("");
		return arrsearch($data,$id);
	}
	function checkCustomer($id,$pass)
	{
		if($this->checkID($id)==-1)
			return 0;
		$this->loadByKey($id);
		if($pass==$this->Pass)
			return 1;
		else
			return 0;
	}
}
?>
